package cn.xz.dao.impl;

import cn.xz.dao.IHappyDao;
import cn.xz.dao.IUserDao;
import cn.xz.entity.Happy;
import cn.xz.entity.Userxx;
import cn.xz.entity.Work;

import java.sql.SQLException;
import java.util.List;
import java.util.Scanner;

public class Chose {
    public void addHappy() throws SQLException {
        IHappyDao iHappyDao = new HappyDaoImpl();
        Happy happy = new Happy();
        happy.setId(10);
        happy.setName("牛逼");
        happy.setAge(58);
        int count=iHappyDao.addHappy(happy);
        System.out.println(count>0?"成功":"失败");
    }
    public void deleteHappy() throws SQLException {
        IHappyDao iHappyDao = new HappyDaoImpl();
        int count=iHappyDao.deleteHappy(4);
        System.out.println(count>0?"成功":"失败");
    }
    public void updateHappy(){
        IHappyDao iHappyDao = new HappyDaoImpl();
        Happy happy = new Happy();
        happy.setId(2);
        happy.setName("小崽子");
        happy.setAge(52);
        int count=iHappyDao.updateHappy(happy);
        System.out.println(count>0?"修改成功":count==0?"未修改":"修改失败");
    }
    public void getAll(){
        IHappyDao iHappyDao = new HappyDaoImpl();
        List<Happy> happys = iHappyDao.getAll();
        for (Happy happy:happys) {
            System.out.println(happy.getName()+"----"+happy.getAge());
        }
    }
    public void getHappyById(){
        IHappyDao iHappyDao = new HappyDaoImpl();
        Happy happy = iHappyDao.getHappyId(2);
        System.out.println(happy.getName()+"----"+happy.getAge());

    }
    public void loginUser(){
        IUserDao iUserDao = new IUserDaoImpl();
        Scanner scanner = new Scanner(System.in);
        System.out.println("输入账号");
        String num =scanner.next();
        System.out.println("输入密码");
        String num1 = scanner.next();
        Userxx userxx = iUserDao.Longin(num,num1);
        //这就是业务
        if(userxx != null ){
            System.out.println("登录成功"+userxx.getUsername());
        }else{
            System.out.println("用户名或密码错误");
        }

    }
    public void userAndDate(){
        IUserDao iUserDao = new IUserDaoImpl();
        List<Userxx> userxxes = iUserDao.getUserAndDept();
        for(Userxx userxx:userxxes){
            System.out.println(userxx.getUsername()+"---"+userxx.getWork().getName());
        }
    }

}
